package com.project.controller;

import com.framework.core.result.APIObjResponse;
import com.framework.core.result.BasePage;
import com.project.base.BaseController;
import com.project.biz.CmsRecoveryOrderBiz;
import com.project.common.model.UserInfo;
import com.project.pojo.dto.AddRecoveryOrderDTO;
import com.project.pojo.dto.RecoveryOrderDTO;
import com.project.pojo.dto.RecoveryOrderDetailDTO;
import com.project.pojo.model.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 回收订单
 * @Author: zhuchi
 * @CreateDate: 2020/11/13 21:41
 * @Version: 1.0
 */
@Api(value = "CmsRecoveryOrderController", description = "回收订单")
@RestController
@RequestMapping("/recoveryOrder")
@Slf4j
public class CmsRecoveryOrderController extends BaseController {

    /**
     * 回收订单业务层接口类
     */
    @Autowired
    private CmsRecoveryOrderBiz recoveryOrderBiz;

    /**
     * 后台-获取回收订单列表
     * @param getRecoveryOrderListModel
     * @return
     */
    @ApiOperation(value = "后台-获取回收订单列表")
    @PostMapping(value = "/getRecoveryOrderList")
    public APIObjResponse<BasePage<RecoveryOrderDTO>> getRecoveryOrderList(@RequestBody GetRecoveryOrderListModel getRecoveryOrderListModel){
        BasePage<RecoveryOrderDTO> basePage = this.recoveryOrderBiz.getRecoveryOrderList(getRecoveryOrderListModel);
        return APIObjResponse.success("查询成功", basePage);
    }

    /**
     * 获取个人回收订单列表
     * @param getRecoveryOrderListModel
     * @return
     */
    @ApiOperation(value = "获取个人回收订单列表")
    @PostMapping(value = "/getMyRecoveryOrderList")
    public APIObjResponse<BasePage<RecoveryOrderDTO>> getMyRecoveryOrderList(@RequestBody GetRecoveryOrderListModel getRecoveryOrderListModel){
        UserInfo userInfo = super.getLoginUser();
        getRecoveryOrderListModel.setUserId(userInfo.getBaseUserId());
        BasePage<RecoveryOrderDTO> basePage = this.recoveryOrderBiz.getRecoveryOrderList(getRecoveryOrderListModel);
        return APIObjResponse.success("查询成功", basePage);
    }

    /**
     * 获取回收订单详情
     * @param recoveryOrderId
     * @return
     */
    @ApiOperation(value = "获取回收订单详情")
    @GetMapping(value = "/getRecoveryOrderDetail")
    public APIObjResponse<RecoveryOrderDetailDTO> getRecoveryOrderDetail(@RequestParam("recoveryOrderId") Long recoveryOrderId){
        RecoveryOrderDetailDTO recoveryOrderDetailDTO = this.recoveryOrderBiz.getRecoveryOrderDetail(recoveryOrderId);
        return APIObjResponse.success("查询成功", recoveryOrderDetailDTO);
    }

    /**
     * 垃圾回收下单
     * @param addRecoveryOrderModel
     * @return
     */
    @ApiOperation(value = "垃圾回收下单")
    @PostMapping(value = "/addRecoveryOrder")
    public APIObjResponse<AddRecoveryOrderDTO> addRecoveryOrder(@Validated @RequestBody AddRecoveryOrderModel addRecoveryOrderModel){
        UserInfo userInfo = super.getLoginUser();
        AddRecoveryOrderDTO addRecoveryOrderDTO = this.recoveryOrderBiz.addRecoveryOrder(addRecoveryOrderModel, userInfo.getBaseUserId());
        return APIObjResponse.success("操作成功", addRecoveryOrderDTO);
    }

    /**
     * 取消回收订单
     * @param cancalRecoveryOrderModel
     * @return
     */
    @ApiOperation(value = "取消回收订单")
    @PostMapping(value = "/cancalRecoveryOrder")
    public APIObjResponse<Integer> cancalRecoveryOrder(@Validated @RequestBody CancalRecoveryOrderModel cancalRecoveryOrderModel){
        UserInfo userInfo = super.getLoginUser();
        int result = this.recoveryOrderBiz.updateCancalRecoveryOrder(cancalRecoveryOrderModel, userInfo.getBaseUserId());
        return APIObjResponse.success("操作成功", result);
    }

    /**
     * 回收员-获取待接单列表
     * @param getBeReceivedRecoveryOrderListModel
     * @return
     */
    @ApiOperation(value = "回收员-获取待接单列表")
    @PostMapping(value = "/getBeReceivedRecoveryOrderList")
    public APIObjResponse<BasePage<RecoveryOrderDTO>> getBeReceivedRecoveryOrderList(@RequestBody GetBeReceivedRecoveryOrderListModel getBeReceivedRecoveryOrderListModel){
        UserInfo userInfo = super.getLoginUser();
        BasePage<RecoveryOrderDTO> basePage = this.recoveryOrderBiz.getBeReceivedRecoveryOrderList(getBeReceivedRecoveryOrderListModel, userInfo.getBaseUserId());
        return APIObjResponse.success("查询成功", basePage);
    }

    /**
     * 回收员-获取接单中、已完成、已取消订单
     * @param getReceivedMemberOrderModel
     * @return
     */
    @ApiOperation(value = "回收员-获取接单中、已完成、已取消订单")
    @PostMapping(value = "/getReceivedMemberOrderList")
    public APIObjResponse<BasePage<RecoveryOrderDTO>> getReceivedMemberOrderList(@RequestBody GetReceivedMemberOrderModel getReceivedMemberOrderModel){
        UserInfo userInfo = super.getLoginUser();
        BasePage<RecoveryOrderDTO> basePage = this.recoveryOrderBiz.getReceivedMemberOrderList(getReceivedMemberOrderModel, userInfo.getBaseUserId());
        return APIObjResponse.success("查询成功", basePage);
    }

    /**
     * 回收员接单
     * @param receivingOrderModel
     * @return
     */
    @ApiOperation(value = "回收员接单")
    @PostMapping(value = "/receivingOrder")
    public APIObjResponse<Integer> receivingOrder(@Validated @RequestBody ReceivingOrderModel receivingOrderModel){
        UserInfo userInfo = super.getLoginUser();
        int result = this.recoveryOrderBiz.updateReceivingOrder(receivingOrderModel, userInfo.getBaseUserId());
        return APIObjResponse.success("操作成功", result);
    }

    /**
     * 回收员确认订单金额
     * @param submitReceiveryOrderModel
     * @return
     */
    @ApiOperation(value = "回收员确认订单金额")
    @PostMapping(value = "/submitReceiveryOrder")
    public APIObjResponse<Integer> submitReceiveryOrder(@Validated @RequestBody SubmitReceiveryOrderModel submitReceiveryOrderModel){
        UserInfo userInfo = super.getLoginUser();
        int result = this.recoveryOrderBiz.updateSubmitReceiveryOrder(submitReceiveryOrderModel, userInfo.getBaseUserId());
        return APIObjResponse.success("操作成功", result);
    }

    /**
     * 评价回收员
     * @param recoveryMemberEvaModel
     * @return
     */
    @ApiOperation(value = "评价回收员")
    @PostMapping(value = "/recoveryMemberEva")
    public APIObjResponse<Integer> recoveryMemberEva(@Validated @RequestBody RecoveryMemberEvaModel recoveryMemberEvaModel){
        UserInfo userInfo = super.getLoginUser();
        int result = this.recoveryOrderBiz.updateRecoveryMember(recoveryMemberEvaModel, userInfo.getBaseUserId());
        return APIObjResponse.success("操作成功", result);
    }

}
